package com.baidu.manager.modules.sys.redis;

import com.baidu.manager.common.utils.RedisUtils;
import com.baidu.manager.modules.sys.entity.SysUserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: jql
 * @description: TODO()
 * @Date: Created by 11:20 2018/4/24
 */
@Component
public class SysUserTokenRedis {
    private static final String NAME = "SysUserToken";

    @Autowired
    private RedisUtils redisUtils;

    public void saveOrUpdate(SysUserToken userToken){
        if(userToken==null){
            return;
        }
        String userId = NAME+userToken.getUserId();
        redisUtils.set(userId, userToken);
    }

    public void delelte(SysUserToken userToken){
        if (userToken==null){
            return;
        }

        redisUtils.delete(NAME+userToken.getUserId());
        redisUtils.delete(NAME+userToken.getToken());
    }

    public SysUserToken get(Object key){
        return redisUtils.get(NAME+key,SysUserToken.class);
    }
}
